package com.iflytek.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iflytek.entity.Coupon;
import com.iflytek.service.CouponService;
import com.iflytek.mapper.CouponMapper;
import org.springframework.stereotype.Service;

/**
 * @author Windows
 * @description 针对表【coupon】的数据库操作Service实现
 * @createDate 2022-09-12 13:20:15
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon>
        implements CouponService {

    @Override
    public PageInfo findByParams(Coupon params, Integer pageNum, Integer pageSize) {

        QueryWrapper<Coupon> w = new QueryWrapper<Coupon>();
        w.like(StringUtils.isNotBlank(params.getGoodName()), "good_name", params.getGoodName());
        w.and(params.getPromotePrice() != null,
                wrapper ->
                        wrapper.eq("promote_price", params.getPromotePrice())
        );
        w.and(StringUtils.isNotBlank(params.getSellerId()),
                wrapper ->
                        wrapper.like("seller_id", params.getSellerId())
        );

        Page<Coupon> page = PageHelper.startPage(pageNum, pageSize);
        this.getBaseMapper().selectList(w);
        return page.toPageInfo();
    }
}




